//
//  TimeButton.m
//  EnjoyPlay
//
//  Created by mac on 16/4/15.
//  Copyright © 2016年 ZY. All rights reserved.
//

#import "TimeButton.h"

@implementation TimeButton
{
    NSTimer *timer;
    UILabel *label1;
    NSInteger _time;
}
- (void)addtimeWithTimeIntValue:(NSInteger)time{
    _time = time;
    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
   
    label1 = [[UILabel alloc] initWithFrame:self.bounds];
    [self addSubview:label1];

    label1.textAlignment = NSTextAlignmentCenter;
    label1.textColor = [UIColor whiteColor];

}

- (void)timerAction{
    
    if (_time > 0) {
        _time--;
        
        label1.text = [NSString stringWithFormat:@"%@ 00:%.2ld:%.2ld",_titleStr,_time/60,_time%60];
        
     
    }else{
        [timer invalidate];
        [label1 removeFromSuperview];
        [timer invalidate];
        if (self.endTimeBlock) {
            self.endTimeBlock();
        }
    }
    
}


- (void)dealloc{
    
    
}



@end
